import os

import requests
import yaml

from interface_practice.frame.utils.log_util import logger, root_path


class BaseApi:
    conf_path = os.sep.join([root_path, '..', '/config/conf.yaml'])
    with open(conf_path, encoding="utf-8") as f:
        cong_data = yaml.safe_load(f)
    _env = os.getenv("test_env")
    BASE_URL = cong_data.get(_env).get("BASE_URL")

    def send(self, method, url, tools, **kwargs):
        '''
        对接口的发起进行封装
        '''
        logger.info(f"method   ===> {method}")
        logger.info(f"url   ===> {url}")
        logger.info(f"tools   ===> {tools}")
        logger.info(f"kwargs   ===> {kwargs}")
        if tools == "requests":
            return requests.request(method, self.BASE_URL + url, **kwargs)
        elif tools == "urllib":
            pass
